import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Shoots out
 * 
 * @author (Anthony Zepperi) 
 * @version (1.8)
 */
public class Arma extends Actor
{
    private int tipo;
    private int distancia;
    private int movimiento;
    private GreenfootImage Lapiz=new GreenfootImage("Lapiz.png");
    private GreenfootImage Granada1=new GreenfootImage("granada1.png");
    private GreenfootImage Granada2=new GreenfootImage("granada2.png");
    private GreenfootImage Granada3=new GreenfootImage("granada3.png");

    public Arma(int direccion,int tipoArma)
    {           
        tipo=tipoArma;
        distancia=0;
        turn(direccion);
        setImage(Lapiz);
        if(tipo==3){setImage(Granada1);movimiento=0;}
        if(tipo==1){setImage(Lapiz);}
    }

    public void act()
    {                     
        if(tipo==1){tipo1();}
        if(tipo==2){tipo2();}
        if(tipo==3){tipo3();}                           
    }

    public void removeEnemigo(){
        Actor pulpo = getOneIntersectingObject(Pulpos.class);
        if (pulpo != null)
        { 
          
            getWorld().addObject(new Animaciones(3),getX()+20,getY());          
            ((Pulpos)pulpo).reduceResistencia();
            getWorld().removeObject(this);
            return;
        }
        Actor aux3 = getOneIntersectingObject(Piranas.class);
        if (aux3 != null)
        {   
           
            getWorld().addObject(new  Animaciones(3),getX()+20,getY());         
            ((Piranas)aux3).reduceResistencia();
            getWorld().removeObject(this);
            return;
        }            
    }

    public void tipo1(){
        move(3);
        if (getX()>=getWorld().getWidth()-1 || getX()<=0 || getY()<=40 || getY()>=getWorld().getHeight()-1){
            getWorld().removeObject(this);
        }else{removeEnemigo();}
    }

    public void tipo2(){
        distancia++;
        move(2);
        if(distancia==50){
            getWorld().addObject(new Arma(0,1),getX(),getY()-30); 
            getWorld().addObject(new Arma(0,1),getX(),getY());
            getWorld().addObject(new Arma(0,1),getX(),getY()+30);           
            getWorld().removeObject(this);
            return;
        }else{removeEnemigo();} 
    }

    public void tipo3(){           
        distancia++;
        move(1);    
        movimiento++;
        if(movimiento==0){setImage(Granada2);}
        if(movimiento==20){setImage(Granada3);}
        if(movimiento==40){setImage(Granada1);movimiento=0;}
        if(distancia==200){
            getWorld().addObject(new Arma(0,1),getX(),getY()); 
            getWorld().addObject(new Arma(45,1),getX(),getY());
            getWorld().addObject(new Arma(90,1),getX(),getY());
            getWorld().addObject(new Arma(135,1),getX(),getY());
            getWorld().addObject(new Arma(180,1),getX(),getY());
            getWorld().addObject(new Arma(225,1),getX(),getY());
            getWorld().addObject(new Arma(270,1),getX(),getY());
            getWorld().addObject(new Arma(315,1),getX(),getY());
            getWorld().removeObject(this);
            return;
        }else{
            
            removeEnemigo();
        
        } 
    }

   
}